﻿using GalaSoft.MvvmLight.CommandWpf;
using HuiZe.education.Common;
using HuiZe.education.Model;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace HuiZe.education.ViewModel
{
    public class FeedbackViewModel : ViewModelBase
    {
        public ObservableCollection<CommonModel> FeedbackTypes { get; set; }
        public CommonModel SelectedFeedbackType { get; set; }
        public string FeedbackContent { get; set; } //反馈意见
        public string ContactModel { get; set; } //联系方式
        public RelayCommand SubmitFeedbackCommand { get; set; }
        private List<string> ImagesPath { get; set; }
        public FeedbackViewModel()
        {
            if (IsInDesignMode)
            {
                FeedbackTypes = new ObservableCollection<CommonModel>()
                {
                    new CommonModel(){ Index=0,Title="功能bug" },
                    new CommonModel(){ Index=1,Title="体验问题"},
                    new CommonModel(){ Index=2,Title="使用建议"},
                    new CommonModel(){ Index=3,Title="其他"},
                };
            }
            FeedbackTypes = new ObservableCollection<CommonModel>()
              {
                  new CommonModel(){ Index=0,Title="功能bug" },
                  new CommonModel(){ Index=1,Title="体验问题"},
                  new CommonModel(){ Index=2,Title="使用建议"},
                  new CommonModel(){ Index=3,Title="其他"},
              };
            SubmitFeedbackCommand = new RelayCommand(SubmitFeedback);
        }

        public void SetImagesPath(string path)
        {
            if (ImagesPath == null) ImagesPath = new List<string>();
            ImagesPath.Add(path);
        }
        private void SubmitFeedback()
        {
          
            Addfeedback();
            

        }



        /// <summary>
        /// 添加反馈信息
        /// </summary>
        private void Addfeedback()
        {

            //Students.Clear();
            reqAddFeedbackModel pamrm = new reqAddFeedbackModel
            {
                content= FeedbackContent,
                type= SelectedFeedbackType.Index,
                contact= ContactModel,
                platform="PC",
                token = HuiZeeducation.Instance.UserInfo.token,

            };
            string data = JsonHelper.ToJson(pamrm);


            var result = Request<ReqStudentList>("/api/feedback/add", data, "添加反馈信息");
            if (result.Item1)
            {
                ShowDialogView("添加成功！");
                MainViewModel homeViewModel = CommonServiceLocator.ServiceLocator.Current.GetInstance<MainViewModel>();
                homeViewModel.Return("");
            }
            else
            {

            }
        }
    }
}
